class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        int res = 0;
        int left = 0;
        int right = 0;
        int n = s.size();

        int hash[1000] = { 0 };

        while (right < n)
        {
            hash[s[right]]++;

            while (hash[s[right]] > 1)
            {
                hash[s[left]]--;
                left++;
            }

            res = max(right - left + 1, res);
            right++;
        }

        return res;
    }
};